<?php

/**
 * Subclass for representing a row from the 'conf_conference' table.
 *
 * 
 *
 * @package lib.model
 */ 
class Conference extends BaseConference
{



#get number of sessions associated to relevant converence
  public function getNbSessions()
  {  
    return $this->countSessions();
  }

#get number of special events associated to relevant converence
  public function getNbSpecialEvents()
  {  
    return $this->countSpecialEvents();
  }

#get number of registrations associated to relevant converence
  public function getNbRegistrations()
  {  
    return $this->countRegistrations();
  }
  
  #get full sessions
  public function countFullsessions(){
	$a = $this->getSessions();
	$count = 0;
	foreach($a as $s){
		if($s->isFull()){
			$count = $count + 1;
		}
	}
	return $count;
  }
  
    #get full EVENTS
  public function countFullevents(){
	$a = $this->getSpecialEvents();
	$count = 0;
	foreach($a as $s){
		if($s->isFull()){
			$count = $count + 1;
		}
	}
	return $count;  
  }

  public function isEarly($registrationDate)
  {
    $registrationEarlyDeadline = $this->getRegistrationEarlyDeadline('m-d-Y');
    
    $dateDiff = myTools::dateDiff('-', $registrationEarlyDeadline, $registrationDate);
    
    if ($dateDiff > 0)
    {
      return true;
    }
    else 
    {
      return false; 
    }
  }
  
  
  public static function isFullDay($conference, $selectedSessions)
  {
  
    $numberOfDaysAttended = Session::getNumberUniqueDays($selectedSessions);
    $numberOfMaximumDays = $conference->getNumberMaximumDays();
    
    if ($numberOfMaximumDays <= $numberOfDaysAttended)
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  
  public function getTotalConferenceFee($early, $memberid, $selectedSessions=null, $selectedSpecialEvents=null)
  {
    //assuming they belonng to the same conference
    $totalConferenceFee = 0;
    $totalSelectedSessionsFee =0;
    $totalSelectedSpecialEventsFee = 0;
    $numberOfDaysAttended = 0;
    $numberOfMaximumDays = $this->getNumberMaximumDays();
    
    if (count($selectedSessions) > 0 )
    {
      if ($selectedSessions)
      {
        $numberOfDaysAttended = Session::getNumberUniqueDays($selectedSessions);
      }
    }
    
    if (count($selectedSpecialEvents) > 0 )
    { 
      if ($selectedSpecialEvents)
      {
        $totalSelectedSpecialEventsFee = SpecialEvent::totalSelectedSpecialEventsFee($selectedSpecialEvents);
      }
    }
    //full conference
    if ($numberOfMaximumDays <= $numberOfDaysAttended)
    {
      //early bird
      if ($early)
      { 
        //member earlybird full
        if ($memberid)
        {
          $totalSelectedSessionsFee = $this->getMemberFeeFullEarly();
        }
        //nonmember earlybird full
        else 
        {
          $totalSelectedSessionsFee = $this->getNonmemberFeeFullEarly();
        }
      }
      //normal reg
      else 
      {
        //member nonearlybird full
        if ($memberid)
        {
          $totalSelectedSessionsFee = $this->getMemberFeeFull();
        }
        //nonmember nonearly full
        else 
        {
          $totalSelectedSessionsFee = $this->getNonmemberFeeFull();
        }
      }
    }
    //partial conference
    else 
    {
      //early bird
      if ($early)
      { 
        //member earlybird partial
        if ($memberid)
        {
          $rate = $this->getMemberFeeDailyEarly();
          $totalSelectedSessionsFee = $rate * $numberOfDaysAttended;
        }
        //nonmember earlybird partial
        else 
        {
          $rate = $this->getNonmemberFeeDailyEarly();
          $totalSelectedSessionsFee = $rate * $numberOfDaysAttended;
        }
      }
      //normal reg
      else 
      {
        //member nonearlybird partial
        if ($memberid)
        {
          $rate = $this->getMemberFeeDaily();
          $totalSelectedSessionsFee=$rate*$numberOfDaysAttended;
        }
        //nonmember nonearly partial
        else 
        {
          $rate = $this->getNonmemberFeeDaily();
          $totalSelectedSessionsFee = $rate * $numberOfDaysAttended;
        }
      }    
    }
    
    $totalConferenceFee = $totalSelectedSessionsFee + $totalSelectedSpecialEventsFee;
    
    return $totalConferenceFee; 
  }
  
  private function getNumberMaximumDays()
  {
    $startDate = $this->getDateStart('m-d-Y');
    $endDate = $this->getDateEnd('m-d-Y');
    
    return myTools::dateDiff('-', $endDate, $startDate);
  }  
  
  #get badges for printing
  public function getDefaultbadges()
  {  
	$criteria = new Criteria();
    $criteria->add(RegistrationPeer::BADGEDATE, null);
    return $this->getRegistrations($criteria);
  }
  
    #get donation total
  public function getDonationtotal()
  {  
	$temp = 0;
    $reg = $this->getRegistrations();
	foreach ($reg as $rr){
		$temp = $temp + $rr->getDonation();
	}
	return $temp;
  }
      #get fee total
  public function getFeetotal()
  {  
	$temp = 0;
    $reg = $this->getRegistrations();
	foreach ($reg as $rr){
		$temp = $temp + $rr->getTotalPaid();
	}
	return $temp;
  }
  

  

  

 

}
